Imports Aricie.DNN.UI.Controls

Namespace Aricie.DNN.Modules.LuceneSearch.UI
    Partial Public Class SlopFilter
        Inherits AricieUserControlBase

#Region "Event Handlers"

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
            If Not Me.IsPostBack Then
                Me.BindLayout()
                Me.ManageVisibility()
            End If
        End Sub

        Protected Sub chkApplySlop_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) _
            Handles chkApplySlop.CheckedChanged
            ManageVisibility()
        End Sub


#End Region


#Region "Public properties"

        Public Property ShowEnable() As Boolean
            Get
                Return Me.trEnabled.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.trEnabled.Visible = value
            End Set
        End Property

        Public Property ShowLabel() As Boolean
            Get
                Return Me.tdLabel.Visible
            End Get
            Set(ByVal value As Boolean)
                Me.tdLabel.Visible = value
            End Set
        End Property

        Public Property SlopRatio() As Integer
            Get
                Return Integer.Parse(Me.ddlSlopRatio.SelectedValue)
            End Get
            Set(ByVal value As Integer)
                Me.ddlSlopRatio.SelectedValue = value.ToString
                If value = 0 Then
                    Me.chkApplySlop.Checked = False
                Else
                    Me.chkApplySlop.Checked = True
                End If
                Me.ManageVisibility()
            End Set
        End Property

        Public Function HasRatio() As Boolean
            Return Not Me.chkApplySlop.Checked AndAlso Integer.Parse(Me.ddlSlopRatio.SelectedValue) <> 0
        End Function

#End Region

#Region "Private methods"

        Private Sub ManageVisibility()
            If Me.chkApplySlop.Checked OrElse Not Me.ShowEnable Then
                Me.divSlopRatio.Visible = True
            Else
                Me.divSlopRatio.Visible = False
            End If
        End Sub

        Private Sub BindLayout()

            For i As Integer = 0 To 4
                ddlSlopRatio.Items.Add(New ListItem(i.ToString, i.ToString))
            Next
            For i As Integer = 5 To 15 Step 5
                ddlSlopRatio.Items.Add(New ListItem(i.ToString, i.ToString))
            Next
            For i As Integer = 20 To 60 Step 20
                ddlSlopRatio.Items.Add(New ListItem(i.ToString, i.ToString))
            Next
            For i As Integer = 100 To 500 Step 200
                ddlSlopRatio.Items.Add(New ListItem(i.ToString, i.ToString))
            Next
            Me.ddlSlopRatio.SelectedIndex = 0

        End Sub

#End Region
    End Class
End Namespace
